import Vue from 'vue'
import Vuex from 'vuex'
import request from "@/utils/request";

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo: {},
  },
  getters: {

  },
  mutations: {
    login(state,userinfo){
        state.userinfo=userinfo
    }
  },
  actions: {
    login(context,userinfo){
      return new Promise((resolve, reject) => {
        request({
          url: '/user/login',
          method: 'post',
          data: userinfo
        }).then(data => {
          console.log(data, "data")
          context.commit('login', data)
          resolve(data)
        }).catch(err => {
          reject(err)
        })
      });
    }
  },
  modules: {
  }
})
